<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			function btn(){
				/*通过id选择器获取文本框的值*/
				//let userObj = document.getElementById("usernameId");
				//alert(userObj.value);
				/*获取所有span标签中的值*/
				/*let spanObjArr = document.getElementsByTagName("span");
                for (let i = 0; i < spanObjArr.length; i++) {
					let spanObj = spanObjArr[i];
					alert(spanObj.innerText); // 获取标签体的内容
                }*/
				/*获取所有class为spanClass的元素对象*/
                /*let spanObjArr = document.getElementsByClassName("spanClass");
                for (let i = 0; i < spanObjArr.length; i++) {
                    let spanObj = spanObjArr[i];
                    alert(spanObj.innerText); // 获取标签体的内容
                }*/
				/*获取name为hobby的元素对象*/
				let hobbyObjArr = document.getElementsByName("hobby");
				alert(hobbyObjArr.length);
			}
		</script>
	</head>
	<body>
		<input type="text" value="tom" id="usernameId" name="username"/><br />
		<input type="checkbox" name="hobby" value="抽烟" />抽烟<br />
		<input type="checkbox" name="hobby" value="喝酒" />喝酒<br />
		<input type="checkbox" name="hobby" value="烫头" />烫头<br />
		<span class="spanClass">佑我中华</span>
		<span class="spanClass">佑我中华1</span>
		<span>佑我中华2</span><br />
		<input type="button" value="获取对象" onclick="btn()" />
	</body>
</html>
